import { addDeptAPI, deleteDeptAPI, fetchDeptAPI, getDeptDetailAPI, updateDeptAPI } from '@/api/deptApi'

const actions = {
  async fetchDeptAction(context, pageParams) {
    const { data } = await fetchDeptAPI(pageParams)
    context.commit('setDeptMutation', data)
  },
  async deleteDeptAction(context, id) {
    const { data } = await deleteDeptAPI(id)
    return data
  },
  async addDeptAction(context, formData) {
    const { data } = await addDeptAPI(formData)
    return data
  },

  async getDeptDetailAction(context, id) {
    const { data } = await getDeptDetailAPI(id)
    return data
  },
  async updateDeptAction(context, fomData) {
    const { data } = await updateDeptAPI(fomData)
    return data
  }
}

const mutations = {
  setDeptMutation(state, { total, rows }) {
    state.deptList = rows
    state.total = total
  }
}

const state = () => {
  return {
    deptList: [],
    total: 0
  }
}

const getters = {}

export default {
  actions,
  mutations,
  state,
  getters,
  namespaced: true
}
